import bianliang from "./bianliang.js";
class Boom {
	constructor(x, y, type) {
		this.x = x;
		this.y = y;
		this.type = type;
		if (this.type == 0) {
			this.imgs = bianliang.resObj.slice(10, 14); 
		} else if (this.type == 1) {
			this.imgs = bianliang.resObj.slice(14, 18); 
		} else if (this.type == 2) {
			this.imgs = bianliang.resObj.slice(18, 24);
		}
		this.width = this.imgs[0].width;
		this.height = this.imgs[0].height;
		this.isPlay = false; 
	}

	draw(ctx) {
		if (this.isPlay == false) {
			this.isPlay = true;    
			var count = 0;
			var id = setInterval(function() {
				ctx.drawImage(this.imgs[count], this.x, this.y, this.width, this.height);
				count++;
				if (count >= this.imgs.length) {
					clearInterval(id); 
					var index =bianliang.boomList.indexOf(this);
					bianliang.boomList.splice(index,1);		
				}
			}.bind(this), 50);
		}

	}
}
export default Boom;
